﻿#pragma once

#include <QObject>
#include <QTimer>
#include <AsCoreProcess>
#include <AsThread>
#include <AsGlobalDataPool>

#include "NewPCIDemoDefine.h"
#include "CoreData.h"
#include "ConfigData.h"
#include "PCIControl.h"
#include "Communicator.h"
#include "DataExportor.h"

class ProcessCore  : public QObject
{
	Q_OBJECT

public:
	ProcessCore(QObject *parent = nullptr);
	~ProcessCore();

	void initCommunicatorFields(HSS::PortInformation portinfo);
	//加载配置文件
	bool loadProfile(QString xmlFilePath);
	//开始
	bool startWork();
	//暂停
	void pauseWork();
	//继续
	void continueWork();
	//停止
	bool stopWork();

	//处理采集到的数据，平均为一幅图
	void averageProcessDataMatAndExtrastGirdle();
	//打开3D窗口之前预处理数据
	void prepareProcess3DDatas();
	  //1.平均值处理
	  void computeAverageMat();
	  //2.转换成3d点云数据
	  void transformToQVector3D();
	  //3.提取束腰矩阵
	  //4.高度集合进行排序
	  void sortHeightList();
	//获得束腰层
	void extrastGirdleLevel();

	void exportToExcel();
	
signals:
	void sendLatestPCIDatas(int index);
	void shouleReleaseButtons();
	void extrastGirdleOver();
	void update3DWidgetSlider();

public slots:
	//void timerStart();
	void dataReadyToUi();

	void onceDataMatsCollectOver(int height);

	void updatePortInformation(HSS::PortInformation portinfo);

	void processOnceDataFromPCI(int index);
	void distributeThreadToPCIData(int index);

private:
	void initialize();
	void initSignalAndSlot();
	void initPCI();

private:
	bool hasLoadedProfile = false;
	PCIControl *m_pPCIctrl;
	Communicator *m_pCommunicator;
	QTimer m_timer;
	bool m_flag = false;
	DataExportor *m_pExcleExportor;

	AsThread *m_pDataProcessThread;
	AsThread *m_pPCIProcessThread;
	AsThread *m_pPCIThread1;
	AsThread *m_pPCIThread2;
	AsThread *m_pPCIThread3;
	AsThread *m_pPCIThread4;
	AsThread *m_pPCIThread5;
	QVector<AsThread*> m_asThreadVec;

};
